package si.yun.web;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import si.yun.common.GuavaCommon;
import si.yun.service.SyNavigation;
import si.yun.utils.GuavaUtils;
import si.yun.utils.JsonData;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: 导航栏web类
 * @Description: TODO
 * @Author: 李振海
 * @Date 2021/7/28 11:39
 */
@RestController
@RequestMapping("Navigation")
@PropertySource({"classpath:config.properties"})
public class SyNavigationController {

    @Autowired
    private SyNavigation service;

   @Autowired
    private GuavaUtils GuavaUtil;

    @Autowired
    private HttpSession session;

    @Value("${path1}")
    private String path;
    /**
     * @Author : 李振海
     * @Date : 2021/7/28 15:23
     * @Param : []
     * @Return : si.yun.utils.JsonData
     * 获取导航栏数据
     */
    @RequestMapping("selNavigation")
    public Map<String,Object> selNavigation(){


        Map<String,Object> user = (Map<String, Object>) session.getAttribute("user");
        user.put("past1",path);


        return user;
    }

    /**
     * @Author : 李振海
     * @Date : 2021/7/29 15:55
     * @Param : [id]
     * @Return : si.yun.utils.JsonData
     * 获取导航栏右上角账户信息
     */
    @RequestMapping("selLoginLog")
    public JsonData selLoginLog(int id){
        List<Map<String,Object>> selLoginLog=service.selLoginLog(id);
        return selLoginLog!=null? JsonData.buildSuccess(selLoginLog): JsonData.buildError("服务器端错误");
    }

    /**
     * @Author : 李振海
     * @Date : 2021/7/29 18:49
     * @Param : [id]
     * @Return : si.yun.utils.JsonData
     * 获取导航栏右上角消息提示
     */
    @RequestMapping("selIndexOrderPrompt")
    public JsonData selIndexOrderPrompt(String id){
        List<Map<String,Object>> selLoginLog=service.selIndexOrderPrompt(id);
        return selLoginLog!=null? JsonData.buildSuccess(selLoginLog): JsonData.buildError("服务器端错误");
    }

    /**
     * @Author : 李振海
     * @Date : 2021/8/6 17:20
     * @Param : [session]
     * @Return : int
     */
    @RequestMapping("/out")
    public JsonData out(HttpSession session){
        session.setAttribute("user","");
        return JsonData.buildSuccess(true);
    }


    /**
     * @author: DZQ
     * @description: 添加登录日志
     * @date: 2021/11/17 8:52
     * @return
     */
    @RequestMapping("/addLogin")
    public JsonData addLogin(String loginLocation,String loginIp,Integer mid){
        int num=service.addLogin(loginLocation,loginIp,mid);
        return num!=0? JsonData.buildSuccess(num): JsonData.buildError("服务器端错误");
    }


}